home *** CD-ROM | disk | FTP | other *** search
/ Almathera Ten Pack 2: CDPD 1 / Almathera Ten on Ten - Disc 2: CDPD 1.iso / pd / 076-100 / 079 / sharedlib / libhead.asm < prev    next >
Assembly Source File  |  1995-03-13  |  5KB  |  175 lines

  1. ;; LibHead.asm
  2. ;;        Copyright 1986, James M Synge
  3. ;;
  4. ;; This file contains the data structures and an
  5. ;; initialization routine.
  6. ;;
  7.     far    code    ; Absolute addresses please.
  8.     far    data    ; Me too!
  9. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  10. ;;
  11. ;; To protect against the library accidentally being invoked
  12. ;; as a program, we return an error value.  This code must
  13. ;; be the first thing in the library.
  14.  
  15.     cseg        ; Code segment
  16.     moveq.l    #20,d0    ; AmigaDOS Fatal Error
  17.     rts
  18. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  19. ;;
  20. ;; Declaration Section:
  21. ;;
  22. ;; Imported Global Variables and Constants:
  23.  
  24.     dseg            ; Data segment
  25.  
  26.     public    _LibraryName    ; char * LibraryName
  27.     public    _LibraryId    ; char * LibraryId
  28.  
  29.     public    LibVersion    ; Current version number.
  30.                 ; Will be checked by
  31.                 ; OpenLibrary() against the
  32.                 ; requested version number.
  33.  
  34.     public    _LibInitBlock    ; Defined in Library.c
  35.  
  36.     public    _SysBase    ; Library Base Pointer for
  37.                 ; exec.library
  38.  
  39. ;; Exported Global Variables:
  40.  
  41.     global    _LibraryBase,4    ; Address of this library.
  42.  
  43.     global    _LibSegList,4    ; Address of first entry in
  44.                 ; this library's seg list.
  45. ;; Imported Functions:
  46.  
  47.     cseg
  48.  
  49.     public    _LibraryInit    ; This is the routine which
  50.                 ; handles most of the
  51.                 ; details of preparing the
  52.                 ; library, except for regs.
  53. ;; Exported Functions:
  54.  
  55.     public    __LibInitCode    ; Referenced by LibInitBlock
  56.                 ; in Library.c
  57.  
  58.     public    _regA6        ; Returns register A6.
  59.  
  60. ;; Constants:
  61. ;; (These should be set in the Amiga supplied include files
  62. ;;  but these aren't available for Manx 3.2a)
  63.  
  64. RTC_MATCHWORD    EQU    $4afc    ; An illegal instruction
  65. RTF_AUTOINIT    EQU    (1 << 7)
  66. NT_LIBRARY    EQU    9    ; As defined in exec/nodes.i
  67.  
  68. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  69. ;;
  70. ;; Resident (RomTag) Structure
  71. ;; This structure must be in the first hunk (AmigaDOS Hunk)
  72. ;; of the library.  Defined in "exec/resident.h"
  73.  
  74. RomTag:
  75.     DC.W    RTC_MATCHWORD    ; This value is an illegal
  76.                 ; instruction.  It is used
  77.                 ; to mark the beginning of a
  78.                 ; rom tag.  The next
  79.                 ; longword confirms it.
  80.  
  81.     DC.L    RomTag        ; The RomTag points to
  82.                 ; itself as confirmation
  83.                 ; that this is a RomTag.
  84.  
  85.     DC.L    EndMarker    ; The address of a location
  86.                 ; after this structure, but
  87.                 ; still in the same hunk.
  88.                 ; The simplest solution is
  89.                 ; to place the label right
  90.                 ; after this structure.
  91.  
  92.     DC.B    RTF_AUTOINIT    ; Auto-initialize flag, see
  93.                 ; Library.c for description
  94.  
  95.     DC.B    LibVersion    ; Library version, will be
  96.                 ; checked against the value
  97.                 ; requested in the
  98.                 ; OpenLibrary() call.
  99.  
  100.     DC.B    NT_LIBRARY    ; This is the Resident
  101.                 ; struct of a library.
  102.  
  103.     DC.B    0        ; Execution priority.
  104.                 ; Not used in libraries.
  105.  
  106.     DC.L    _LibraryName    ; Pointer to library name.
  107.  
  108.     DC.L    _LibraryId    ; Pointer to full library id
  109.  
  110.     DC.L    _LibInitBlock    ; Pointer to initialization
  111.                 ; descriptor block or code.
  112.                 ; See Library.c
  113. ;;    End of the RomTag
  114.  
  115. EndMarker    ; Simplest place for this marker
  116.  
  117. ; See Interface.asm for a complete explanation of:
  118. AztecBugList:    reg    a4/a6
  119.  
  120. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  121. ;;
  122. ;; LibInitCode, is called from within MakeLibrary(), after
  123. ;; all the memory has been allocated, the jump table has
  124. ;; been constructed, and the InitStruct() call has been
  125. ;; made.  It is identified as the initialization code by
  126. ;; LibInitBlock in Library.c.  LibraryInit() returns the
  127. ;; value (in D0 as per the calling standard) which is then
  128. ;; returned to MakeLibrary().  If it is zero, the library
  129. ;; wouldn't be added to the exec's library list and thus
  130. ;; cann't be opened.
  131.  
  132. __LibInitCode:
  133.     move.l    a6,_SysBase    ; Store away these three
  134.                 ; registers which tell us
  135.     move.l    d0,_LibraryBase    ; we are and where the rest
  136.     move.l    a0,_LibSegList    ; of the world can be found.
  137.  
  138.     ; Forgive me, Oh Lord, for I have sinned...
  139.     movem.l    AztecBugList,-(sp)
  140.  
  141.     ; Now call the C routine LibraryInit() with the
  142.     ; address of our Library struct as its only argument.
  143.  
  144.     move.l    d0,-(sp)    ; Push LibraryBase
  145.     jsr    _LibraryInit    ; Call
  146.     addq.l    #4,sp        ; Pop LibraryBase
  147.  
  148.     ; Restore the registers
  149.     movem.l    (sp)+,AztecBugList
  150.  
  151.     rts            ; Now return to our caller.
  152.  
  153. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  154. ;;
  155. ;; This trite little routine is included so that those
  156. ;; library specific routines which wish to access the struct
  157. ;; Library may do so by calling regA6() in order to get the
  158. ;; value of the Library Base Pointer.
  159. ;; Example Code Fragment:
  160. ;;
  161. ;;        struct Library *lib, *regA6();
  162. ;;        lib = regA6();
  163. ;;        return(lib -> lib_IdString);
  164. ;;
  165. ;; An alternate (and perhaps safer method) is to use the
  166. ;; _LibraryBase global variable which is setup by the
  167. ;; __LibInitCode routine.
  168.  
  169.     public _regA6
  170. _regA6:    move.l    a6,d0
  171.     rts
  172.  
  173.     ds.w    0    ; Align to a word boundary
  174.         END
  175.